﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Printing;
using System.Text;
using System.Threading.Tasks;

namespace TemplatesPrint
{
    public class test1
    {
        #region 方式2
        /// <summary>
        /// 获取打印机的状态编码(方式2)
        /// </summary>
        /// <returns></returns>
        public static int GetPrinterStatusCodeInt2(string p)
        {
            int statusCode = 0;
            PrintQueue queue = new LocalPrintServer().GetPrintQueue(p);
            //PrintQueue queue = new LocalPrintServer().DefaultPrintQueue;
            if (queue.IsNotAvailable)
            {
                statusCode = 1;
                return statusCode;
            }
            if (queue.IsOutOfPaper)
            {
                statusCode = 2;
                return statusCode;
            }

            if (queue.IsBusy)
            {
                statusCode = 3;
                return statusCode;
            }
            if (queue.IsInError)
            {
                statusCode = 4;
                return statusCode;
            }
            if (queue.IsOffline)
            {
                statusCode = 5;
                return statusCode;
            }
            if (queue.IsOutOfMemory)
            {
                statusCode = 6;
                return statusCode;
            }
            if (queue.HasPaperProblem)
            {
                statusCode = 7;
                return statusCode;
            }
            if (queue.IsPaused)
            {
                statusCode = 8;
                return statusCode;
            }

            return statusCode;
        }

        /// <summary>
        /// 检查打印机是否可用(方式2)
        /// </summary>
        /// <param name="intStatusCodeValue">打印机状态编码</param>
        /// <returns></returns>
        public static bool CheckIsEnable2(int intStatusCodeValue)
        {
            bool isEnable = false;
            if (intStatusCodeValue == 0)
            {
                return true;
            }
            return isEnable;
        }


        /// <summary>
        /// 获取打印机的状态信息(方式2)
        /// </summary>
        /// <param name="intStatusCodeValue">打印机状态编码</param>
        /// <returns></returns>
        public static string GetPrinterStatusMessage2(int intStatusCodeValue)
        {
            string strRet = string.Empty;
            switch (intStatusCodeValue)
            {
                case 1:
                    strRet = "打印机不可用";
                    break;
                case 2:
                    strRet = "打印机缺纸";
                    break;
                case 3:
                    strRet = "打印机正忙";
                    break;
                case 4:
                    strRet = "打印机正在处于错误状态";
                    break;
                case 5:
                    strRet = "打印机处于脱机状态";
                    break;
                case 6:
                    strRet = "打印机内存溢出";
                    break;
                case 7:
                    strRet = "遇到了未指定的纸张错误";
                    break;
                case 8:
                    strRet = "打印机打印队列暂停了";
                    break;
                default:
                    strRet = "未知状态（Unknown Status）";
                    break;
            }
            return strRet;
        }

        /// <summary>
        /// 获取打印队列的任务数(方式2)
        /// </summary>
        /// <returns></returns>
        public static int GetTaskNumber2()
        {
            return new LocalPrintServer().DefaultPrintQueue.NumberOfJobs;
        }
        #endregion
    }
}
